//
// Created on 2024/8/6.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be
// found, please include "napi/native_api.h".

#ifndef ARKUI_C_API_TLANG_LIST_ITEM_H
#define ARKUI_C_API_TLANG_LIST_ITEM_H

#include "ArkUIListItemNode.h"
#include "../tlang/tvm/rt_code/NativeMethodTable.h"
#include "TLangText.h"
#include <memory>

using std::shared_ptr;

class ListItemWrapper {
    shared_ptr<NativeModule::ArkUIListItemNode> target;

public:
    ListItemWrapper() { target = std::make_shared<NativeModule::ArkUIListItemNode>(); }

    static void bind(shared_ptr<RtCode::NativeMethodTable> nativeMethodTable) {
        nativeMethodTable->add("ListItem", "create", create);
        nativeMethodTable->add("ListItem", "addChild", addChild);
    }

    shared_ptr<NativeModule::ArkUIListItemNode> getTarget() { return target; }

    static void create(RtData::Frame &frame) {
        auto *wrapper = new ListItemWrapper();
        frame.pushRef(reinterpret_cast<RtData::Object *>(wrapper));
    }

    static void addChild(RtData::Frame &frame) {
        auto *self = frame.getSlot(0).getRef();
        auto *wrapper = reinterpret_cast<ListItemWrapper *>(self);
        auto arg = reinterpret_cast<TextWrapper *>(frame.popRef());
        wrapper->target->AddChild(arg->getTarget());
    }
};

#endif // ARKUI_C_API_TLANG_LIST_ITEM_H
